package com.nuc.seckill.service.impl;

import cn.hutool.core.lang.Assert;
import com.nuc.seckill.dao.SeckillUserDao;
import com.nuc.seckill.model.SeckillUser;
import com.nuc.seckill.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author spider
 */
@Service("userService")
@Slf4j
public class UserServiceImpl implements UserService {

    @Resource
    private SeckillUserDao seckillUserDao;

    /**
     * 查询邮箱是否注册
     *
     * @param email 用户邮箱
     * @return com.nuc.seckill.model.SeckillUser
     * @author 石一歌
     * @date 2022/8/4 22:50
     */
    @Override
    public SeckillUser findByEmail(String email) {
        Assert.notNull(email);
        SeckillUser seckillUser = new SeckillUser();
        seckillUser.setEmail(email);
        List<SeckillUser> list = seckillUserDao.list(seckillUser);
        if (!CollectionUtils.isEmpty(list)) {
            Assert.isTrue(list.size() == 1);
            return list.get(0);
        }
        return null;
    }
}
